<template>
	<view class="content">
		<view class="data" v-if="itemList.length>0">
			<view class="yy-doctor-box yy-doctor-box2">
				<view class="yy-doctor-item2" v-for="(item,index) in itemList" @click="goDoctorHome(item)">
					<view class="pic-box">
						<image :src="item.avatar" mode="aspectFill"></image>
					</view>
					<view class="doctor-name">{{ item.name }}</view>
					<view class="doctor-des yy-text-line yy-text-line2"> {{ item.desc }}</view>
				</view>
			</view>
			<view class='loadingicon acea-row row-center-wrapper' @click="clickMore">
				<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
			</view>
		</view>
		<view class="nodata" v-else>
			<emptyPage title="暂无数据～"></emptyPage>
		</view>
	</view>
</template>

<script>
	import {getHotDoctor} from '@/api/inquiry.js'
	import emptyPage from '@/components/emptyPage.vue';
	import {
		mapGetters
	} from "vuex";
	export default {
		computed: {
			...mapGetters(['routeError']),
		},

		components:{
			emptyPage
		},
		data() {
			return {
				loadTitle: '加载更多',
				loading: false,
				loadend: false,
				where:{'page':1,'limit':20},
				itemList:[],
			}
		},
		onLoad() {
			if(this.routeError) {
				this.$store.commit('GO_ERROR');
				return
			}
			this.getList();
			
		},
		onPullDownRefresh(){
			console.log('rk==>refresh')
			this.loadend = false;
			this.where.page = 1;
			this.clickMore();
		},
		onReachBottom() {
			this.clickMore();
		},
		methods:{
			
			/**
			 * 列表
			 */
			getList(){
				let that = this;
				
				getHotDoctor(that.where).then(res => {
					uni.stopPullDownRefresh();
							
					if(that.where.page == 1){
						that.itemList = [];
					}
					let resList = res.data.list;
					let allCount = res.data.count;
					that.itemList = that.$util.SplitArray(resList, that.itemList);
					that.$set(that, 'itemList', that.itemList);
					let loadend = that.itemList.length >= allCount;
					
					console.log('rk==>[xx]'+allCount + '[xx]'+that.itemList.length+'[bool]'+loadend);
					
					that.loadend = loadend;
					that.loadTitle = loadend ? '我也是有底线的' : '加载更多';
					that.where.page += 1;
					that.loading = false;
				});
				
			},
			/**
			 * 更多
			 */
			clickMore(){
				if(this.loadend){
					uni.stopPullDownRefresh();
					return
				}
				this.getList();
			},
			/**
			 * 医生主页
			 */
			goDoctorHome(item){
				uni.navigateTo({
					url:'/pages/shops/subs_inquiry/doctor/index?doctor_id='+item.id,
				});
			}
		}
	}
</script>

<style lang="scss"> 
	.content {
		
		.data {
			padding: 20rpx 30rpx;
			background-color: #fff;
		}
	}
</style>